<template>
	<view class="content">
		<view class="steeting">
			<view class="xiyi" @tap='toXieyi'>
				<view>用户协议</view>
				<view>></view>
			</view>
			<view class="line"></view>
			<view class="nicheng" @tap='updateNickname'>
				<view>修改昵称</view>
				<view>></view>
			</view>
			<view class="line"></view>
			<view class="nicheng" @tap='toupdatephone'>
				<view>修改密码</view>
				<view>></view>
			</view>
		</view>
		<view class="login-out" @tap='loginOut'>
			{{btnName}}
		</view>
		
		
		<view class="box" v-if="show"  @tap="coneal"></view>
		
		<view class="modal" v-if="show">
			<view class="title">
				修改昵称
			</view>
			<view class="content1">
				<input type="text" v-model="nickname">
			</view>
			<view class="btn-group">
				<view class="coneal" @tap="coneal">取消</view>
				<view class="submit" @tap="comfim">确认</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickname:'',
				show:false,
				btnName:'退出登录'
			}
		},
		onLoad(options) {
			let userinfo = uni.getStorageSync('userinfo');
			
			if(!userinfo){
				this.btnName = '登录'
			}
			this.nickname = options.nickname
		},
		methods: {
			toXieyi(){
				uni.navigateTo({
					url:'/pages/my/agreement'
				})
			},
			updateNickname(){
				this.show = true
			},
			toupdatephone(){
				uni.navigateTo({
					url:'/pages/my/updataphone'
				})
			},
			comfim(){
				if(this.nickname == ''){
					uni.showToast({
						title:"名称不能为空",
						icon:"none"
					})
					return
				}
				
				let userinfo = uni.getStorageSync('userinfo')
				
				this.$api.interfaceApi('updateNickname')({
					'id':userinfo.id,
					'nickname':this.nickname
				}).then(res=>{
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
					if(res.code == 1){
						this.show = false
					}
				})
			},
			coneal(){
				this.show = false
			},
			loginOut(){
				uni.setStorageSync('userinfo','');
				uni.navigateTo({
					url:'/pages/register/register'
				})
			},
		}
	}
</script>

<style lang="less">
	.content{
		padding: 50rpx 0;
		
		.steeting{
			background-color: #FFFFFF;
			padding: 30rpx;
			.xiyi{
				display: flex;
				justify-content: space-between;
				line-height: 50rpx;
			}
			
			.line{
				border-top: 1rpx solid #e5e5e5;
				margin: 30rpx 0;
			}
			
			.nicheng{
				display: flex;
				justify-content: space-between;
				line-height: 50rpx;
			}
			
		}
		
		.login-out{
			background-color: #FFFFFF;
			padding: 30rpx;
			margin-top: 30rpx;
			text-align: center;
			color: #ff0000;
		}
		
		.box{
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color:#000000;
			opacity: 0.5;
			z-index: 9998;
		}
		.modal{
			background-color: #FFFFFF;
			border-radius: 15rpx;
			width: 70%;
			height: 260rpx;
			position: absolute;
			top: 35%;
			left: 15%;
			z-index: 9999;
			padding: 20rpx;
			box-sizing: border-box;
			.title{
				text-align: center;
				padding: 10rpx 0;
				font-size: 36rpx;
				box-sizing: border-box;
			}
			.content1{
				height: 70rpx;
				background-color: #f5f5f5;
				input{
					height: 70rpx;
					line-height: 70rpx;
					padding: 0 10rpx;
					box-sizing: border-box; 
				}
			}
			.btn-group{
				display: flex;
				height: 80rpx;
				line-height: 80rpx;
				margin-top: 10rpx;
				.coneal{
					width: 50%;
					text-align: center;
				}
				.submit{
					color: #007AFF;
					width: 50%;
					text-align: center;
				}
			}
		}
	}

</style>
